package export.pet
{
	import base.*;
	
	import com.dusk.util.ResUtil;
	import com.game.data.vo.PetDataVO;
	import com.greensock.*;
	
	import export.bullet.*;
	
	import flash.display.*;
	import flash.geom.*;
	
	public class PetDragon2 extends BasePet
	{
		
		public function PetDragon2(param1:BaseHero, param2:PetDataVO)
		{
			this.fenshenArray = [];
			super(param1, param2);
			this.horizonSpeed = 5;
			this.attackBackInfoDict["hit1"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [6, -5],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "physics"
			};
			this.attackBackInfoDict["hit2"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-8, -5],
				"attackInterval" : 8,
				"power"          : 12,
				"attackKind"     : "physics"
			};
			this.attackRange = 150;
			this.setAction("idle");
			this.skillCD1 = [gc.frameClips * 2, gc.frameClips * 20];
			this.skillCD2 = [gc.frameClips * 5, gc.frameClips * 10];
		}
		
		public var continueCount:int = 0;
		public var totalHurt:int = 0;
		private var type:int = 0;
		private var fenshenArray:Array;
		
		override protected function initBBDC():void
		{
			var _loc1_:* = null;
			var _loc2_:Array = BaseBitmapDataPool.getBitmapDataArrayByName("PetDragonBmd2");
			if (_loc2_)
			{
				_loc1_ = {
					"name"  : "body",
					"source": _loc2_
				};
				bbdc = new BaseBitmapDataClip([_loc1_], 200, 200, new Point(0, 0));
				bbdc.setOffsetXY(1, -5);
				bbdc.setFrameStopCount([[2, 2, 2, 3, 2, 4], [4, 4, 4, 4], [8], [2, 2, 2, 2, 10], [2, 2, 2, 10], [2, 2, 2, 2, 10], [30]]);
				bbdc.setFrameCount([6, 4, 1, 5, 4, 5, 1]);
				bbdc.setEnterFrameCallBack(this.enterFrameFunc, this.exitFrameFunc);
				bbdc.setAddScriptWhenFrameOver(this.scriptFrameOverFunc);
				this.bodyContainer.addChild(bbdc);
				return;
			}
			throw new Error("PetDragonBmd2--BitmapData Error!");
		}
		
		override protected function initCollideArea():void
		{
			this.colipse = ResUtil.getNewObj("ObjectBaseSprite4") as Sprite;
			this.colipse.visible = false;
			this.addChild(this.colipse);
		}
		
		override public function setAction(param1:String):void
		{
			super.setAction(param1);
			var _loc2_:Point = this.bbdc.getCurPoint();
			switch (param1)
			{
				case "idle":
					if (_loc2_.y != 0)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(0);
					}
					this.bbdc.setState(param1);
					break;
				case "walk":
					if (_loc2_.y != 1)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(1);
					}
					this.bbdc.setState(param1);
					break;
				case "hurt":
					if (_loc2_.y != 2)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(2);
					}
					this.bbdc.setState(param1);
					break;
				case "hit1":
					if (_loc2_.y != 4)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(4);
					}
					this.bbdc.setState(param1);
					break;
				case "hit2":
					if (_loc2_.y != 5)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(5);
					}
					this.bbdc.setState(param1);
					break;
				case "hit3":
					if (_loc2_.y != 6)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(6);
					}
					this.bbdc.setState(param1);
					break;
				case "dead":
					if (_loc2_.y != 3)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(3);
					}
					this.bbdc.setState(param1);
			}
		}
		
		override protected function scriptFrameOverFunc(param1:int):void
		{
			var _loc2_:String = this.bbdc.getState();
			switch (_loc2_)
			{
				case "walk":
					this.bbdc.setFramePointX(0);
					break;
				case "idle":
					this.bbdc.setFramePointX(0);
					break;
				case "hit1":
					this.setAction("idle");
					break;
				case "hit2":
					this.setAction("idle");
					break;
				case "hit3":
					this.setStatic();
					this.setAction("idle");
					break;
				case "hurt":
					this.setStatic();
					this.setAction("idle");
					break;
				case "dead":
					this.destroy();
			}
		}
		
		override protected function enterFrameFunc(param1:Point):void
		{
			var _loc2_:String = this.bbdc.getState();
			var _loc3_:uint = this.getBBDC().getDirect();
			var _loc4_:Point = new Point();
			switch (_loc2_)
			{
				case "hit1":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 3)
						{
							if (this.bbdc.getCurFrameCount() == 10)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x - 30;
								}
								else
								{
									_loc4_.x = this.x + 30;
								}
								_loc4_.y = this.y;
								this.doHit1(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit2":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 4)
						{
							if (this.bbdc.getCurFrameCount() == 2)
							{
								this.doHit2(_loc3_, _loc4_);
								break;
							}
							break;
						}
						break;
					}
					break;
				case "hit3":
					if (gc.isSingleGame() || gc.sid == this.sourceRole.sid)
					{
						if (param1.x == 0)
						{
							if (this.bbdc.getCurFrameCount() == 24)
							{
								if (_loc3_ == 0)
								{
									_loc4_.x = this.x;
								}
								else
								{
									_loc4_.x = this.x;
								}
								_loc4_.y = this.y + 10;
								this.doHit3(_loc3_, _loc4_);
							}
						}
						if (_loc3_ == 0)
						{
							this.velocity.x = -10;
							break;
						}
						this.velocity.x = 10;
						break;
					}
			}
		}
		
		override protected function beforeSkill1Start():Boolean
		{
			if (this.type == 0)
			{
				return getMp() >= this._petInfo.findPetUsedMagic("fs") && Boolean(this._petInfo.findHasStudySkill("fs"));
			}
			return false;
		}
		
		override protected function beforeSkill2Start():Boolean
		{
			return Boolean(this._petInfo.findHasStudySkill("sdcc")) && getMp() >= this._petInfo.findPetUsedMagic("sdcc") && this.curAttackTarget != null && AUtils.GetDisBetweenTwoObj(this, this.curAttackTarget) <= 5 * 60;
		}
		
		override public function reduceHp(param1:int, param2:Boolean = false):void
		{
			super.reduceHp(param1, param2);
		}
		
		override protected function releSkill1():void
		{
			this.faceToTarget();
			
			this.setAction("hit2");
			this.lastHit = "hit2";
			_petInfo.reduceMp(this._petInfo.findPetUsedMagic("fs"));
		}
		
		override protected function releSkill2():void
		{
			this.faceToTarget();
			
			this.setAction("hit3");
			this.lastHit = "hit3";
			_petInfo.reduceMp(this._petInfo.findPetUsedMagic("sp"));
		}
		
		override protected function checkBuffSkill():void
		{
			if (this.type == 0)
			{
				super.checkBuffSkill();
				
			}
		}
		
		override protected function normalHit():void
		{
			this.faceToTarget();
			
			this.setAction("hit1");
			this.lastHit = "hit1";
		}
		
		override public function getRealPower(param1:String, param2:Boolean = true):int
		{
			var _loc3_:* = null;
			var _loc4_:uint = this.getCriteValue(param2) ? 2 : uint(1);
			var _loc5_:uint = uint(this.getMagicAddValue());
			var _loc6_:Number = this.isGXP ? 1.2 : Number(1);
			switch (param1)
			{
				case "hit1":
					return (this.getAtk() + _loc5_) * _loc4_ * _loc6_;
				case "hit2":
					_loc3_ = this._petInfo.getPetHarmObj("sdcc");
					if (_loc3_)
					{
						return (_loc3_.first + _loc5_) * _loc4_ * _loc6_;
					}
					return 0;
					break;
				default:
					return 0;
			}
		}
		
		override protected function exitFrameFunc(param1:Point):void
		{
		}
		
		override protected function myIntelligence():void
		{
			var _loc1_:* = null;
			var _loc2_:* = null;
			var _loc3_:int = 0;
			if (!this.isBeAttacking())
			{
				super.myIntelligence();
			}
			if (this.type == 1)
			{
				if (this.continueCount > 0)
				{
					--this.continueCount;
					if (this.continueCount == 0)
					{
						this.destroy();
					}
				}
			}
			else if (this.type == 0)
			{
				_loc1_ = [];
				for each (_loc2_ in this.fenshenArray)
				{
					if (_loc2_.continueCount > 0)
					{
						_loc2_.step();
					}
					if (_loc2_.continueCount == 0 || _loc2_.petInfo.getHp() <= 0)
					{
						if (_loc2_.continueCount == 0)
						{
							this.cureHp(_loc2_.totalHurt);
						}
						_loc1_.push(_loc2_);
					}
				}
				if (_loc1_.length > 0)
				{
					for each (_loc2_ in _loc1_)
					{
						_loc3_ = int(this.fenshenArray.indexOf(_loc2_));
						if (_loc3_ != -1)
						{
							this.fenshenArray.splice(_loc3_, 1);
						}
					}
				}
			}
		}
		
		override public function isCanMoveWhenAttack():Boolean
		{
			return this.curAction == "hit3";
		}
		
		override protected function isCannotMoveWhenAttackOnFloor():Boolean
		{
			return this.curAction == "hit1" || this.curAction == "hit2";
		}
		
		override public function destroy():void
		{
			var pd1:PetDragon2 = null;
			var i:int = 0;
			var bb:BaseBullet = null;
			if (this.type == 0)
			{
				for each (pd1 in this.fenshenArray)
				{
					pd1.destroy();
				}
				super.destroy();
			}
			else
			{
				if (this.bbdc)
				{
					this.bbdc.destroy();
				}
				if (this.curAddEffect)
				{
					this.curAddEffect.destroy();
					this.curAddEffect = null;
				}
				this.isReadyToDestroy = true;
				TweenMax.to(this, 1, {
					"alpha"           : 0,
					"onComplete"      : function (param1:BasePet):*
					{
						if (param1.parent)
						{
							param1.parent.removeChild(param1);
						}
					},
					"onCompleteParams": [this]
				});
				i = 0;
				while (i < this.magicBulletArray.length)
				{
					bb = this.magicBulletArray[i] as BaseBullet;
					bb.destroy();
					i++;
				}
				this.magicBulletArray = [];
				if (this.sourceRole)
				{
					this.sourceRole = null;
				}
			}
			this.fenshenArray.length = 0;
		}
		
		public function setContinueTime(param1:int):void
		{
			this.continueCount = param1;
			if (param1 > 0)
			{
				this.type = 1;
			}
		}
		
		private function doHit1(param1:uint, param2:Point):void
		{
			var _loc3_:SpecialEffectBullet = new SpecialEffectBullet("PetDragon2Bullet1");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			if (this.type == 1)
			{
				_loc3_.setFuncWhenHitTarget(this.addHurt);
			}
			_loc3_.setAction("hit1");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
		
		private function addHurt(param1:BaseBullet):void
		{
			this.totalHurt += param1.hurt;
		}
		
		private function doHit2(param1:uint, param2:Point):void
		{
			var _loc3_:PetDataVO = _petInfo.clone();
			var _loc4_:PetDragon2;
			(_loc4_ = new PetDragon2(this.sourceRole, _loc3_)).setContinueTime(gc.frameClips * 10);
			_loc4_.alpha = 0.5;
			_loc4_.x = this.x + (Math.random() - 0.5) * 300;
			_loc4_.y = this.y - 50;
			gc.gameScene.addChild(_loc4_);
			this.fenshenArray.push(_loc4_);
		}
		
		private function doHit3(param1:uint, param2:Point):void
		{
			var _loc3_:FollowTargetBullet = new FollowTargetBullet("PetDragon2Bullet2");
			_loc3_.x = param2.x;
			_loc3_.y = param2.y;
			_loc3_.setOwner(this);
			_loc3_.setDirect(param1);
			if (this.type == 1)
			{
				_loc3_.setFuncWhenHitTarget(this.addHurt);
			}
			_loc3_.setAction("hit2");
			gc.gameScene.addChild(_loc3_);
			this.magicBulletArray.push(_loc3_);
		}
	}
}
